﻿#include <iostream>
#include<cmath>
using namespace std;
string s = "0123456789ABCDEF";
void xtom(int x,int m)
{
	if (x >= m)
	{
		xtom(x / m, m);
	}
	cout << s[x % m];
}
int main()
{
	int x, n;
	cin >> x >> n;
	xtom(x, n);
	return 0;
}
//float f(float x, int n)
//{
//	if (n == 1)
//		return x*1.0/(1+x);
//	else
//		return x*1.0 / (n + f(x, n - 1));
//}
//int main()
//{
//	float x;
//	int n;
//	cin >> x >> n;
//	printf("%.2f\n", f(x, n));
//	return 0;
//}
//double f(int x, int n)
//{
//	if (n == 1)
//	{
//		return sqrt(1 + x);
//	}
//	else
//	{
//		return sqrt(n + f(x, n - 1));
//	}
//}
//int main()
//{
//	int x, n;
//	cin >> x >> n;
//	printf("%.2f\n",f(x, n));
//	return 0;
//}
//int digit(int n,int k)
//{
//	if (k == 1)
//	{
//		return n % 10;
//	}
//	else
//	{
//		return digit(n / 10, k - 1);
//	}
//}
//int main()
//{
//	int n, k;
//	cin >> n >> k;
//	int ret = digit(n, k);
//	cout << ret << endl;
//	return 0;
//}

//int akm(int m, int n)
//{
//	if (m == 0)
//		return n + 1;
//	if (m > 0 && n == 0)
//	{
//		return akm(m - 1, 1);
//	}else
//		return akm(m - 1, akm(m, n - 1));
//}
//int main()
//{
//	int m, n;
//	cin >> m >> n;
//	int ret = akm(m, n);
//	cout << ret << endl;
//	return 0;
//}
//int sum(int n)
//{
//    if (n == 1)
//        return 1;
//    else
//        return n + sum(n - 1);
//}
//int main()
//{
//    int n = 0;
//    cin >> n;
//    cout << sum(n) << endl;
//    return 0;
//}
//#include <iostream>
//using namespace std;
//int sum(int n)
//{
//    if (n == 1)
//        return 1;
//    else
//        return n + sum(n - 1);
//}
//int main()
//{
//    int n = 0;
//    cin >> n;
//    cout << sum(n) << endl;
//    return 0;
//}
////#include <iostream>
////using namespace std;
////int Fib(int n)
////{
////    int a = 1;
////    int b = 1;
////    int c = 1;
////    while (n > 2)
////    {
////        c = a + b;
////        a = b;
////        b = c;
////        n--;
////    }
////    return c;
////}
////int count = 0;
////int Fib(int n)
////{
////    if (n == 3)
////        count++;//统计第3个斐波那契数被计算的次数
////    if (n <= 2)
////        return 1;
////    else
////        return Fib(n - 1) + Fib(n - 2);
////}
////int main()
////{
////    int n = 0;
////    cin >> n;
////    int ret = Fib(n);
////    cout << ret << endl;
////    cout << "count = " << count << endl;
////    return 0;
////}
////#include <iostream>
////using namespace std;
////int main()
////{
////    int n = 0;
////    cin >> n;
////    int ret = Fib(n);
////    cout << ret << endl;
////    return 0;
////}
////#include <iostream>
////using namespace std;
////int Fib(int n)
////{
////    if (n <= 2)
////        return 1;
////    else
////        return Fib(n - 1) + Fib(n - 2);
////}
////int Fact(int n)
////{
////    int i = 0;
////    int ret = 1;
////    for (i = 1; i <= n; i++)
////    {
////        ret *= i;
////    }
////    return ret;
////}
////int Fact(int n)
////{
////    if (n == 0)
////        return 1;
////    else
////        return n * Fact(n - 1);
////}
////int main()
////{
////    int n = 0;
////    cin >> n;
////    int ret = Fact(n);
////    cout << ret << endl;
////    return 0;
////}
////int Fact(int n)
////{
////    if (n == 0)
////        return 1;
////    else
////        return n * Fact(n - 1);
////}
////int main()
////{
////    cout << "hehe" << endl;
////    main();//main函数中⼜调⽤了main函数
////    return 0;
////}
////#include <iostream>
////#include <cmath>
////using namespace std;
////int reverse_int(int n)
////{
////    int ret = 0;
////    while (n)
////    {
////        ret = ret * 10 + n % 10;
////        n /= 10;
////    }
////    return ret;
////}
////int is_prime(int n)
////{
////    int i = 0;
////    if (n < 2)
////        return false;
////    for (i = 2; i <= sqrt(n); i++)
////    {
////        if (n % i == 0)
////            return false;
////    }
////    return true;
////}
////int main()
////{
////    int m = 0;
////    int n = 0;
////    cin >> m >> n;
////    int i = 0;
////    int flag = 0;
////    for (i = m; i <= n; i++)
////    {
////        int i2 = reverse_int(i);
////        if (is_prime(i) && is_prime(i2))
////        {
////            if (flag)
////                cout << ",";
////            cout << i;
////            flag++;
////        }
////    }
////    if (flag == 0)
////        cout << "No" << endl;
////    return 0;
////}
////#include <iostream>
////#include <cmath>
////using namespace std;
////bool is_prime(int n)
////{
////    int j = 0;
////    if (n < 2)
////        return false;
////    for (j = 2; j <= sqrt(n); j++)
////    {
////        if (n % j == 0)
////            return false;
////    }
////    return true;
////}
////int ishuiwen(int n)
////{
////    int tmp = n;
////    int ret = 0;
////    while (tmp)
////    {
////        ret = ret * 10 + tmp % 10;
////        tmp /= 10;
////    }
////    return ret == n;
////}
////int main()
////{
////    int n = 0;
////    cin >> n;
////    int i = 0;
////    int cnt = 0;
////    for (i = 11; i <= n; i++)
////    {
////        if (is_prime(i) && ishuiwen(i))
////            cnt++;
////    }
////    cout << cnt << endl;
////    return 0;
////}
////bool isprime(int n)
////{
////	int j = 0;
////	if (n < 2)
////	{
////		return false;
////	}
////	for (j = 2; j <= sqrt(n); j++)
////	{
////		if (n % j == 0)
////		{
////			return false;
////		}
////	}
////	return true;
////}
////int main()
////{
////	int n = 0;
////	cin >> n;
////	int i = 0;
////	int flag = 0;
////	for (i = 2; i + 2 <= n; i++)
////	{
////		if (isprime(i) && isprime(i + 2))
////		{
////			cout << i << " " << i + 2 << endl;
////			flag++;
////		}
////	}
////	if (flag == 0)
////	{
////		cout << "empty" << endl;
////	}
////	return 0;
////}